$().ready(function() {
	validateRule();

});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/ticket/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("服务器异常，请联系管理员");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("添加停车券成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				parent.layer.alert(data.msg)
			}
		}
	});

}
jQuery.validator.addMethod("minNumber",function(value, element){
    var returnVal = true;
    inputZ=value;
    var ArrMen= inputZ.split(".");    //截取字符串
    if(ArrMen.length==2){
        if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
            returnVal = false;
            return false;
        }
    }
    return returnVal;
},"小数点后最多为两位");         //验证错误信息

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			price : {
				required : true,
				number : true,
                min:0,
                max:9999,
                minNumber: $("#price").val()
			},
            minute : {
                required : true,
                digits:true,
                min:1,
                max:9999
            },
            ticketName : {
                required : true,
                maxlength:50
            }
		},
		messages : {
			price : {
				required : icon + "价格必填且必须是数字",
                minNumber: icon +"价格最多精确到小数点后两位"
			},
            minute : {
                required : icon + "抵用时长必填"
            },
            ticketName : {
                required : icon + "停车券名称必填",
                maxlength : icon + "停车券名称最大长度50个字符"
            }
		}
	})
}


